/*
 * @Author: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Date: 2025-09-08 13:26:40
 * @LastEditTime: 2025-09-08 14:20:39
 * @LastEditors: fuhongliang-TSJ hongliang.fu@4d-bios.com
 * @Description: 
 * @FilePath: \lc_-esp32_-s3\main\test\test_camera.c
 * 立创实战派ESP32-S3开发板
 * Copyright (c) 2025 by 4D Bios, All Rights Reserved. 
 */

#include "test_camera.h"
#include "lcd.h"
#include "yingwu.h"

static const char *TAG = "test_camera";

 // 定义lcd显示队列句柄
static QueueHandle_t xQueueLCDFrame = NULL;

extern esp_lcd_panel_handle_t panel_handle;

// lcd处理任务
static void task_process_lcd(void *arg)
{
    camera_fb_t *frame = NULL;

    while (1)
    {
        if (xQueueReceive(xQueueLCDFrame, &frame, portMAX_DELAY))
        {
            esp_lcd_panel_draw_bitmap(panel_handle, 0, 0, frame->width, frame->height, (uint16_t *)frame->buf);
            esp_camera_fb_return(frame);
        }
    }
}

// 摄像头处理任务
static void task_process_camera(void *arg)
{
    while (1)
    {
        camera_fb_t *frame = esp_camera_fb_get();
        if (frame)
            xQueueSend(xQueueLCDFrame, &frame, portMAX_DELAY);
    }
}

 /**
 * @description: 测试camera 摄像头数据放到LCD屏显示
 * @return {*}
 */
void test_camera(i2c_obj_t self)
{
    bsp_lcd_init();
    lcd_draw_pictrue(0, 0, 320 ,240, gImage_yingwu);
    vTaskDelay(500 / portTICK_PERIOD_MS);  // 延时500毫秒
    
    camera_init(self);

    xQueueLCDFrame = xQueueCreate(2, sizeof(camera_fb_t *));
    xTaskCreatePinnedToCore(task_process_camera, "task_process_camera", 2 * 1024, NULL, 5, NULL, 1);
    xTaskCreatePinnedToCore(task_process_lcd, "task_process_lcd", 2 * 1024, NULL, 5, NULL, 1);
}